package cloud.common.redis.redis.service.impl;

import cloud.common.redis.redis.service.IRedisListService;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author czq
 * @param <T>
 */
@Service
public class RedisListServiceImpl<T> extends RedisServiceImpl implements IRedisListService<T> {


    @Override
    public void setList(String key, List<T> value) {
        ListOperations<String,Object> vo = this.redisTemplate.opsForList();
        vo.rightPush(key, value);
    }

    @Override
    public List<T> getListRange(String key, int start, int end) {
        ListOperations listOperations =this.redisTemplate.opsForList();
        List<T> list = (List<T>)listOperations.range(key,start,end);
        //批量删除左边用的
        for (int i=start;i<end+1;i++){
            listOperations.leftPop(key);
        }
       return list;
    }
}